package com.czk.classreader;


import org.objectweb.asm.ClassReader;
import org.objectweb.asm.util.ASMifier;
import org.objectweb.asm.util.Printer;
import org.objectweb.asm.util.Textifier;
import org.objectweb.asm.util.TraceClassVisitor;

import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/8/4 16:45
 */
public class ParsingOptionsTest {
    public static void main(String[] args) throws IOException {
        String filePath = "com.czk.sample.Test";
        // 会根据传入值的不同会忽略一些信息，所以生成的asm代码会不同
        // 刚开始推荐使用 ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES
        int parsingOptions = ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES;
        //
        boolean asmCode = true;
        // 拿到打印类
        Printer printer = asmCode ? new ASMifier() : new Textifier();
        PrintWriter out = new PrintWriter(System.out, true);
        TraceClassVisitor traceClassVisitor = new TraceClassVisitor(null, printer, out);
        new ClassReader(filePath).accept(traceClassVisitor, parsingOptions);
    }
}
